import http from '../../util/http';
import * as api from '../../util/api';
const state ={
    GoodsDadaDetail:[]
};
const actions={
    DataDetail({commit},id){  //查询商品详情
        let clientId=sessionStorage.getItem('clientId')
        return http({
            url:api.DataDetail,
            method:'post',
            data:{clientId:clientId,
                   goodsId:id,
            }
        }).then(res=>{
            commit('queryGoodsDetail',res.data.data)
            // console.log(res.data.data.isFavorites)
            return res.data.data //将数据返回给页面，处理异步
        }).catch(err=>{
            console.log(err)
        })
    },
    AddCollent({commit},id){         //添加商品到收藏夹
        let clientId=sessionStorage.getItem('clientId')
        return http({
            url:api.AddCollent,
            method:'post',
            data:{
                  clientId:"7bff3ee541e746f786623dfc7bb39cfb",
                  goodsId:id,
            }
        }).then(res=>{
            commit('addCollection',res.data.code)
            // console.log(res.data)
            return res.data.data //将数据返回给页面，处理异步
        })
    },
    DelCollent({commit},id){         //取消收藏
        let clientId=sessionStorage.getItem('clientId')
        return http({
            url:api.DelCollent,
            method:'post',
            data:{clientId:clientId,
                  goodsId:id,
            }
        }).then(res=>{
            commit('delCollection',res.data.msg)
            return res.data.msg //将数据返回给页面，处理异步
        })
    }
};
const mutations ={
    queryGoodsDetail(state,obj){
        state.GoodsDadaDetail = obj
    },
    addCollection(state,obj){
        state.addDada = obj
    },
    delCollection(state,obj){
        state.delDada = obj
    },
};
export default{
    state,
    actions,
    mutations,
}